home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / GADGET.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  11KB  |  383 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.13  $
  6. //
  7. // Base class TGadget and simple derived TSeparatorGadget.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_GADGET_H)
  10. #define OWL_GADGET_H
  11.  
  12. #if !defined(OWL_WINDOW_H)
  13. # include <owl/window.h>
  14. #endif
  15. #if !defined(OWL_DC_H)
  16. # include <owl/dc.h>
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. class _OWLCLASS TGadgetWindow;
  24.  
  25. //
  26. // Ids of some OWL predefined gadgets
  27. //
  28. #define IDG_FIRST       30000   // first predefined gadget ID
  29. #define IDG_LAST        31000   // last predefined gadget ID
  30. #define IDG_MESSAGE     IDG_FIRST + 0    // + 0 is for backwards compatability
  31. #define IDG_STATUS_EXT  IDG_FIRST + 1
  32. #define IDG_STATUS_CAPS IDG_FIRST + 2
  33. #define IDG_STATUS_NUM  IDG_FIRST + 3
  34. #define IDG_STATUS_SCRL IDG_FIRST + 4
  35. #define IDG_STATUS_OVR  IDG_FIRST + 5
  36. #define IDG_STATUS_REC  IDG_FIRST + 6
  37. #define IDG_SIZEGRIP    IDG_FIRST + 7    // The ID for a size grip gadget
  38.  
  39. // Generic definitions/compiler options (eg. alignment) preceeding the 
  40. // definition of classes
  41. #include <services/preclass.h>
  42.  
  43. //
  44. // struct TMargins
  45. // ~~~~~~ ~~~~~~~~
  46. // Margin units & dimensions used by class TGadgetWindow and class TGadget.
  47. //
  48. struct _OWLCLASS TMargins {
  49.   enum TUnits {Pixels, LayoutUnits, BorderUnits};
  50.  
  51.   TUnits  Units;
  52.  
  53.   int  Left;
  54.   int  Right;
  55.   int  Top;
  56.   int  Bottom;
  57.  
  58.   TMargins() {Units = LayoutUnits; Left = Right = Top = Bottom = 0;}
  59.  
  60.   TMargins(TUnits u, int l, int r, int t, int b)
  61.       {Units = u; Left = l; Right = r; Top = t; Bottom = b;}
  62.  
  63.   void GetPixels(int& left, int& right, int& top, int& bottom, int fontHeight) const;
  64. };
  65.  
  66. //
  67. // class TGadget
  68. // ~~~~~ ~~~~~~~
  69. // Gadgets have outer borders and margins within, belong to a gadget window
  70. // in a gadget list, and have their own coordinate system.
  71. //
  72. // Margins are the same as for TGadgetWindow and borders are always in
  73. // border units
  74. //
  75. // Default behavior for gadgets is to shrink wrap to "fit" around their
  76. // contents you can control this by setting "ShrinkWrapWidth" and
  77. // "ShrinkWrapHeight"
  78. //
  79. #if defined(BI_NO_RTTI)
  80. class _OWLCLASS TGadget : public TStreamableBase {
  81. #else
  82. class _OWLCLASS TGadget {
  83. #endif
  84.   public:
  85.     // Gadget border styles. These match TIUBorder's TStyles exactly
  86.     //
  87.     enum TBorderStyle {
  88.       None,             //  No border painted at all
  89.       Plain,            //  Plain plain window frame
  90.       Raised,           //  Status field style raised
  91.       Recessed,         //  Status field style recessed
  92.       Embossed,         //  Grouping raised emboss bead
  93.       Grooved,          //  Grouping groove
  94.       ButtonUp,         //  Button in up position
  95.       ButtonDn,         //  Button in down position
  96.       WndRaised,        //  Raised window outer+inner edge
  97.       WndRecessed,      //  Input field & other window recessed
  98.       WellSet,          //  Well option set (auto grows + 1)
  99.     };
  100.  
  101.     TGadget(int id = 0, TBorderStyle borderStyle = None);
  102.     virtual ~TGadget();
  103.  
  104.     // Border dimensions
  105.     //
  106.     struct TBorders {
  107.       uint  Left   : 8;
  108.       uint  Right  : 8;
  109.       uint  Top    : 8;
  110.       uint  Bottom : 8;
  111.  
  112.       TBorders() {Left = Right = Top = Bottom = 0;}
  113.     };
  114.  
  115.     int            GetId() const;
  116.  
  117.     // Typically you would either choose a border style (which automatically
  118.     // sets the individual border edges) or set the borders and then override
  119.     // member function PaintBorder() to create a custom look
  120.     //
  121.     // NOTE: changing the borders, margins, or border style all end up invoking
  122.     //       the gadget window's GadgetChangedSize() member function
  123.     //
  124.     void           SetBorders(const TBorders& borders);
  125.     TBorders&      GetBorders();
  126.  
  127.     void           SetMargins(const TMargins& margins);
  128.     TMargins&      GetMargins();
  129.  
  130.     void           SetBorderStyle(TBorderStyle bs);
  131.     TBorderStyle   GetBorderStyle() const;
  132.  
  133.     TRect&         GetBounds();
  134.  
  135.     virtual void   SetEnabled(bool enabled);
  136.     bool           GetEnabled() const;
  137.  
  138.     void           SetVisible(bool visible);
  139.     bool           IsVisible() const;
  140.  
  141.     void           SetEndOfRow(bool eor);
  142.     bool           IsEndOfRow() const;
  143.  
  144.     // Simply sets the corresponding member data.
  145.     //
  146.     void           SetShrinkWrap(bool shrinkWrapWidth, bool shrinkWrapHeight);
  147.  
  148.     // Directly alters the size of the gadget.
  149.     //
  150.     void           SetSize(TSize& size);
  151.  
  152.     // Get the size that this gadget would like to be
  153.     //
  154.     virtual void   GetDesiredSize(TSize& size);
  155.  
  156.     // Returns the amount of space in pixels taken up by the borders and
  157.     // margins
  158.     //
  159.     void           GetOuterSizes(int& left, int& right, int& top, int& bottom);
  160.  
  161.     // Returns the area excluding the borders and margins
  162.     //
  163.     void           GetInnerRect(TRect& rect);
  164.  
  165.     // Set the bounding rectangle for this gadget
  166.     //
  167.     virtual void   SetBounds(const TRect& rect);
  168.  
  169.     virtual bool   IdleAction(long idleCount);
  170.     virtual void   CommandEnable();
  171.     virtual void   SysColorChange();
  172.  
  173.     TGadget*       NextGadget();
  174.  
  175.   protected:
  176.  
  177.     // The following virtual methods are called to allow the gadget
  178.     // to initialize, cleanup or update any internal information
  179.     // when its inserted into a window, moved or removed.
  180.     //
  181.     virtual void   Created();
  182.     virtual void   Inserted();
  183.     virtual void   Moved();
  184.     virtual void   Removed();
  185.  
  186.     void           Invalidate(bool erase = true);
  187.     void           InvalidateRect(const TRect& rect, // receiver's coord system
  188.                                   bool  erase = true);
  189.     void           Update();  // Paint now if possible
  190.  
  191.     // Default behavior returns true if the point is within the receiver's
  192.     // bounding rect. "point" is in the receiver's coordinate system
  193.     //
  194.     virtual bool   PtIn(const TPoint& point);
  195.  
  196.     virtual void   Paint(TDC& dc);
  197.  
  198.     // Self sent by method Paint(). Override this is if you want to
  199.     // implement a border style that isn't supported
  200.     //
  201.     virtual void   PaintBorder(TDC& dc);
  202.  
  203.     // Mouse virtuals forwarded from TGadgetWindows message handlers.
  204.     // "point" is in the receiver's coordinate system.
  205.  
  206.     // MouseMove is only called if the mouse is captured. Enter & leave when
  207.     // mouse enters & leaves a gadget & is not captured.
  208.     //
  209.     virtual void   MouseEnter(uint modKeys, TPoint& point);
  210.     virtual void   MouseMove(uint modKeys, TPoint& point);
  211.     virtual void   MouseLeave(uint modKeys, TPoint& point);
  212.  
  213.     // Captures the mouse if "TrackMouse" is set.
  214.     //
  215.     virtual void   LButtonDown(uint modKeys, TPoint& point);
  216.     virtual void   RButtonDown(uint modKeys, TPoint& point);
  217.  
  218.     // Releases the mouse capture if "TrackMouse" is set.
  219.     //
  220.     virtual void   LButtonUp(uint modKeys, TPoint& point);
  221.     virtual void   RButtonUp(uint modKeys, TPoint& point);
  222.  
  223.   // Data members -- will become private
  224.   //
  225.   public_data:
  226.     bool             Clip;         // Does this gadget need clip rgn set? false
  227.     bool             WideAsPossible;  // Should this gadget be made wide? false
  228.  
  229.   protected_data:
  230.     TGadgetWindow*   Window;          // The window that this gadget is in
  231.     TRect            Bounds;          // The bounding rectangle of this gadget
  232.     TBorderStyle     BorderStyle;     // Style of border to use
  233.     TBorders         Borders;         // Size of each of the 4 borders
  234.     TMargins         Margins;         // Size & units of the 4 margins within
  235.     bool             ShrinkWrapWidth; // Shrink the width to fit contents?
  236.     bool             ShrinkWrapHeight;// Shrink the height to fit contents?
  237.     bool             TrackMouse;      // Should gadget capture the mouse? false
  238.     int              Id;              // Integer id of this gadget
  239.  
  240.   private:
  241.     TGadget*         Next;
  242.     enum {
  243.       Enabled  = 0x01,
  244.       Visible  = 0x02,
  245.       EndOfRow = 0x04,
  246.     };
  247.     uint16           Flags;           // Enabled, EndOfRow flags
  248.  
  249.     // Hidden to prevent accidental copying or assignment
  250.     //
  251.     TGadget(const TGadget&);
  252.     TGadget& operator =(const TGadget&);
  253.  
  254.   friend class _OWLCLASS TGadgetList;   // Access to Next for containment
  255.   friend class _OWLCLASS TGadgetWindow; // Access to Next for containment
  256.   DECLARE_CASTABLE;
  257. };
  258.  
  259. //
  260. // class TSeparatorGadget
  261. // ~~~~~ ~~~~~~~~~~~~~~~~
  262. // Simple helper class that you can use when you want a separator between
  263. // gadgets. You specify the size of the separator and the separator disables
  264. // itself and turns off shrink wrapping
  265. //
  266. // "size" is used for both the width and the height
  267. //
  268. class _OWLCLASS TSeparatorGadget : public TGadget {
  269.   public:
  270.     TSeparatorGadget(int size = 0, int id = 0);
  271.     void   Inserted();
  272. };
  273.  
  274. //
  275. // class TSizeGripGadget
  276. // ~~~~~ ~~~~~~~~~~~~~~~
  277. // A gadget that is used on the far right of a status bar to provide re-sizing
  278. // grip for the host window.
  279. //
  280. class _OWLCLASS TSizeGripGadget : public TSeparatorGadget {
  281.   public:
  282.     TSizeGripGadget(int id = IDG_SIZEGRIP);
  283.     void Paint(TDC& dc);
  284. };
  285.  
  286. // Generic definitions/compiler options (eg. alignment) following the 
  287. // definition of classes
  288. #include <services/posclass.h>
  289.  
  290. #if defined(BI_NAMESPACE)
  291. } // namespace OWL
  292. #endif
  293.  
  294. //----------------------------------------------------------------------------
  295. // Inline implementations
  296. //
  297.  
  298. //
  299. // Return the Id of the gadget
  300. //
  301. inline int TGadget::GetId () const {
  302.   return Id;
  303. }
  304.  
  305. //
  306. // Return the current border of the gadget
  307. //
  308. inline TGadget::TBorders& TGadget::GetBorders() {
  309.   return Borders;
  310. }
  311.  
  312. //
  313. // Return the margins of the gadget
  314. //
  315. inline TMargins& TGadget::GetMargins() {
  316.   return Margins;
  317. }
  318.  
  319. //
  320. // Return the borderstyle the gadget is using
  321. //
  322. inline TGadget::TBorderStyle TGadget::GetBorderStyle() const {
  323.   return BorderStyle;
  324. }
  325.  
  326. //
  327. // Return the bounds of the gadget
  328. //
  329. inline TRect& TGadget::GetBounds() {
  330.   return Bounds;
  331. }
  332.  
  333. //
  334. // Return true if the gadget is enabled
  335. //
  336. inline bool TGadget::GetEnabled() const {
  337.   return Flags & Enabled;
  338. }
  339.  
  340. //
  341. // Change the visibility of the gadget
  342. //
  343. inline void TGadget::SetVisible(bool visible) {
  344.   if (visible)
  345.     Flags |= Visible;
  346.   else
  347.     Flags &= ~Visible;
  348. }
  349.  
  350. //
  351. // Return true if the gadget is visible
  352. //
  353. inline bool TGadget::IsVisible() const {
  354.   return Flags & Visible;
  355. }
  356.  
  357. //
  358. // Set the end of row property for the gadget
  359. // The end of row property is used to tile gadgets
  360. //
  361. inline void TGadget::SetEndOfRow(bool eor) {
  362.   if (eor)
  363.     Flags |= EndOfRow;
  364.   else
  365.     Flags &= ~EndOfRow;
  366. }
  367.  
  368. //
  369. // Return true if this gadget is at the end of a row
  370. //
  371. inline bool TGadget::IsEndOfRow() const {
  372.   return Flags & EndOfRow;
  373. }
  374.  
  375. //
  376. // Return the next gadget after this one
  377. //
  378. inline TGadget* TGadget::NextGadget() {
  379.   return Next;
  380. }
  381.  
  382. #endif  // OWL_GADGET_H
  383.